<?php

namespace GamesBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @author  coffey  <coffey@nligo.com>
 * User
 *
 * 用户主表
 * @ORM\Table(name="user")
 * @ORM\Entity(repositoryClass="GamesBundle\Repository\UserRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class User implements UserInterface
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer",options={"comment":"用户ID"})
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="user_total_score", type="decimal", precision=10, scale=2, nullable=false,options={"comment":"用户可用分数"})
     */
    private $userTotalScore = '0.00';

    /**
     * @var string
     *
     * @ORM\Column(name="safe_total_score", type="decimal", precision=10, scale=2, nullable=false,options={"comment":"用户保险柜分数"})
     */
    private $safeTotalScore = '0.00';

    /**
     * @ORM\Column(type="string", unique=true,name="username",options={"comment":"用户名"})
     */
    private $username = '';

    /**
     * @ORM\Column(type="string",name="nickname",options={"comment":"用户昵称"})
     */
    private $nickname = '';

    /**
     * @ORM\Column(type="string",name="headimg",options={"comment":"用户头像"})
     */
    private $headimg = '';

    /**
     * @ORM\Column(type="string",name="password",options={"comment":"用户密码"})
     */
    private $password;


    /**
     * @ORM\Column(type="string",name="email",options={"comment":"用户邮箱"})
     */
    private $email = '';


    /**
     * @ORM\Column(type="json_array",name="roles",options={"comment":"用户角色"})
     */
    private $roles = array();

    /**
     * @var integer
     * @ORM\Column(type="integer",name="enabled",options={"comment":"用户状态"})
     */
    private $enabled = '0';

    /**
     * @var integer
     * @ORM\Column(type="integer",name="is_activate",options={"comment":"用户激活状态 0为未激活 1为激活"})
     */
    private $isActivate = '0';

    /**
     * @var integer
     * @ORM\Column(type="integer",name="is_full",options={"comment":"资料完整度 0为未补全 1为完整"})
     */
    private $isFull = '0';

    /**
     * @var integer
     * @ORM\Column(type="integer",name="create_time",options={"comment":"创建时间"})
     */
    public $createTime = "";

    /**
     * @var string
     * @ORM\Column(type="string",name="inv_code",length=100,options={"comment":"邀请码"})
     */
    public $invCode = "";

    /**
     * @var string
     * @ORM\Column(type="string",name="yunxin_id",length=100,options={"comment":"云信ID"})
     */
    public $yunxinId = "";

    /**
     * @var string
     * @ORM\Column(type="string",name="yunxin_token",length=100,options={"comment":"云信token"})
     */
    public $yunxinToken = "";

    
    /**
     * @ORM\OneToOne(targetEntity="UserProfile", mappedBy="userId")
     */
    private $profile;

    /**
     * @ORM\PrePersist
     */
    public function PrePersist()
    {
        $this->setCreateTime(time());
    }

    public function getId()
    {
        return $this->id;
    }

    /**
     * {@inheritdoc}
     */
    public function getUsername()
    {
        return $this->username;
    }

    public function setUsername($username)
    {
        $this->username = $username;
    }

    /**
     * {@inheritdoc}
     */
    public function getPassword()
    {
        return $this->password;
    }

    public function setPassword($password)
    {
        $this->password = $password;
    }

    /**
     * Returns the roles or permissions granted to the user for security.
     */
    public function getRoles()
    {
        $roles = $this->roles;
        // guarantees that a user always has at least one role for security
        if (empty($roles)) {
            $roles[] = 'ROLE_USER';
        }
        return array_unique($roles);
    }

    /**
     * @param String
     */
    public function setRole($role)
    {
        $this->roles[] = $role;
    }

    /**
     * @param array
     */
    public function setRoles(array $roles)
    {
        $this->roles = (array)$roles;
    }

    /**
     * Returns the salt that was originally used to encode the password.
     */
    public function getSalt()
    {
        // See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html
        // we're using bcrypt in security.yml to encode the password, so
        // the salt value is built-in and you don't have to generate one
        return;
    }

    /**
     * Removes sensitive data from the user.
     */
    public function eraseCredentials()
    {
        // if you had a plainPassword property, you'd nullify it here
        // $this->plainPassword = null;
    }

    /**
     * Set enabled
     *
     * @param integer $enabled
     *
     * @return User
     */
    public function setEnabled($enabled)
    {
        $this->enabled = $enabled;
        return $this;
    }

    /**
     * Get enabled
     *
     * @return integer
     */
    public function getEnabled()
    {
        return $this->enabled;
    }

    /**
     * Set nickname
     *
     * @param string $nickname
     *
     * @return User
     */
    public function setNickname($nickname)
    {
        $this->nickname = $nickname;
        return $this;
    }

    /**
     * Get nickname
     *
     * @return string
     */
    public function getNickname()
    {
        return $this->nickname;
    }

    /**
     * Set createtime
     *
     * @param integer $createtime
     *
     * @return Message
     */
    public function setCreateTime($createtime)
    {
        $this->createTime = $createtime;
        return $this;
    }

    /**
     * Get createtime
     *
     * @return integer
     */
    public function getCreateTime()
    {
        return $this->createTime;
    }

    /**
     * Set email
     *
     * @param string $email
     *
     * @return User
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set isActivate
     *
     * @param integer $isActivate
     *
     * @return User
     */
    public function setIsActivate($isActivate)
    {
        $this->isActivate = $isActivate;

        return $this;
    }

    /**
     * Get isActivate
     *
     * @return integer
     */
    public function getIsActivate()
    {
        return $this->isActivate;
    }

    /**
     * Set isFull
     *
     * @param integer $isFull
     *
     * @return User
     */
    public function setIsFull($isFull)
    {
        $this->isFull = $isFull;

        return $this;
    }

    /**
     * Get isFull
     *
     * @return integer
     */
    public function getIsFull()
    {
        return $this->isFull;
    }

    /**
     * Set headimg
     *
     * @param string $headimg
     *
     * @return User
     */
    public function setHeadimg($headimg)
    {
        $this->headimg = $headimg;

        return $this;
    }

    /**
     * Get headimg
     *
     * @return string
     */
    public function getHeadimg()
    {
        return $this->headimg;
    }

    /**
     * Set userTotalScore
     *
     * @param string $userTotalScore
     *
     * @return User
     */
    public function setUserTotalScore($userTotalScore)
    {
        $this->userTotalScore = $userTotalScore;

        return $this;
    }

    /**
     * Get userTotalScore
     *
     * @return string
     */
    public function getUserTotalScore()
    {
        return $this->userTotalScore;
    }

    /**
     * Set safeTotalScore
     *
     * @param string $safeTotalScore
     *
     * @return User
     */
    public function setSafeTotalScore($safeTotalScore)
    {
        $this->safeTotalScore = $safeTotalScore;

        return $this;
    }

    /**
     * Get safeTotalScore
     *
     * @return string
     */
    public function getSafeTotalScore()
    {
        return $this->safeTotalScore;
    }

    /**
     * Set profile
     *
     * @param \GamesBundle\Entity\UserProfile $profile
     *
     * @return User
     */
    public function setProfile(\GamesBundle\Entity\UserProfile $profile = null)
    {
        $this->profile = $profile;

        return $this;
    }

    /**
     * Get profile
     *
     * @return \GamesBundle\Entity\UserProfile
     */
    public function getProfile()
    {
        return $this->profile;
    }

    /**
     * Set invCode
     * @param  integer $id
     *
     * @return User
     */
    public function setInvCode($id)
    {
        $this->invCode = $id.'_'.substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, 6);

        return $this;
    }

    /**
     * Get invCode
     *
     * @return string
     */
    public function getInvCode()
    {
        return $this->invCode;
    }

    /**
     * Set yunxinId
     *
     * @param string $yunxinId
     *
     * @return User
     */
    public function setYunxinId($yunxinId)
    {
        $this->yunxinId = $yunxinId;

        return $this;
    }

    /**
     * Get yunxinId
     *
     * @return string
     */
    public function getYunxinId()
    {
        return $this->yunxinId;
    }

    /**
     * Set yunxinToken
     *
     * @param string $yunxinToken
     *
     * @return User
     */
    public function setYunxinToken($yunxinToken)
    {
        $this->yunxinToken = $yunxinToken;

        return $this;
    }

    /**
     * Get yunxinToken
     *
     * @return string
     */
    public function getYunxinToken()
    {
        return $this->yunxinToken;
    }
}
